package com.yehongyu.mytools.ui.applet;

import java.applet.Applet;
import java.awt.Button;
import java.awt.TextArea;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class TextAreaApplet extends Applet implements ActionListener {

	/** 序列ID */
	private static final long serialVersionUID = 1L;

	Button b1 = new Button("Text Area 1");
	Button b2 = new Button("Text Area 2");
	Button b3 = new Button("Replace Text");
	Button b4 = new Button("Insert Text");

	TextArea t1 = new TextArea("t1", 1, 30);
	TextArea t2 = new TextArea("t2", 4, 30);

	public void init() {
		setSize(300, 300);
		add(b1);
		add(t1);
		add(b2);
		add(t2);
		add(b3);
		add(b4);
		b1.addActionListener(this);
		b2.addActionListener(this);
		b3.addActionListener(this);
		b4.addActionListener(this);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if (e.getSource().equals(b1)) {
			getAppletContext().showStatus(t1.getText());
		} else if (e.getSource().equals(b2)) {
			t2.setText("Inserted by Button 2");
			t2.append(": " + t1.getText());
			getAppletContext().showStatus(t2.getText());
		} else if (e.getSource().equals(b3)) {
			String s = " Replacement ";
			t2.replaceRange(s, 3, 3 + s.length());
		} else if (e.getSource().equals(b4)) {
			t2.insert(" Inserted ", 10);
		} else {
			System.out.println("Object is [" + e.getSource()
					+ "],Unknown Action!");
		}
	}

}
